package com.itheima.project.web;


import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.project.basic.ResponseWrap;
import com.itheima.project.core.enums.content.ContentChannelEnum;
import com.itheima.project.face.ContentChannelFace;
import com.itheima.project.utils.ResponseWrapBuild;
import com.itheima.project.vo.content.ContentChannelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * @Description：交易渠道表前端控制器
 */
@Slf4j
@Api(tags = "交易渠道表controller")
@RestController
@RequestMapping("content-channel")
public class ContentChannelController {

    @Autowired
    ContentChannelFace contentChannelFace;

    /***
     * @description 多条件查询交易渠道表分页列表
     * @param contentChannelVo 交易渠道表Vo查询条件
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @return: Page<ContentChannelVo>
     */
    @PostMapping("page/{pageNum}/{pageSize}")
    @ApiOperation(value = "交易渠道表分页",notes = "交易渠道表分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "contentChannelVo",value = "交易渠道表Vo对象",required = true,dataType = "ContentChannelVo"),
        @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
        @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    public ResponseWrap<Page<ContentChannelVo>> findContentChannelVoPage(
                                    @RequestBody ContentChannelVo contentChannelVo,
                                    @PathVariable("pageNum") int pageNum,
                                    @PathVariable("pageSize") int pageSize) {
        Page<ContentChannelVo> contentChannelVoPage = contentChannelFace.findContentChannelVoPage(contentChannelVo, pageNum, pageSize);
        return ResponseWrapBuild.build(ContentChannelEnum.SUCCEED,contentChannelVoPage);
    }

    /**
     * @Description 保存交易渠道表
     * @param contentChannelVo 交易渠道表Vo对象
     * @return ContentChannelVo
     */
    @PutMapping
    @ApiOperation(value = "添加ContentChannel",notes = "添加ContentChannel")
    @ApiImplicitParam(name = "contentChannelVo",value = "交易渠道表Vo对象",required = true,dataType = "ContentChannelVo")
    public ResponseWrap<ContentChannelVo> createContentChannel(@RequestBody ContentChannelVo contentChannelVo) {
        ContentChannelVo contentChannelVoResult = contentChannelFace.createContentChannelVo(contentChannelVo);
        return ResponseWrapBuild.build(ContentChannelEnum.SUCCEED,contentChannelVoResult);
    }

    /**
     * @Description 修改交易渠道表
     * @param contentChannelVo 交易渠道表Vo对象
     * @return Boolean 是否修改成功
     */
    @PatchMapping
    @ApiOperation(value = "修改交易渠道表",notes = "修改交易渠道表")
    @ApiImplicitParam(name = "contentChannelVo",value = "交易渠道表Vo对象",required = true,dataType = "ContentChannelVo")
    public ResponseWrap<Boolean> updateContentChannel(@RequestBody ContentChannelVo contentChannelVo) {
        Boolean flag = contentChannelFace.updateContentChannelVo(contentChannelVo);
        return ResponseWrapBuild.build(ContentChannelEnum.SUCCEED,flag);
    }

    /**
     * @Description 删除交易渠道表
     * @param contentChannelVo 刪除条件：checkedIds 不可为空
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "删除交易渠道表",notes = "删除交易渠道表")
    @ApiImplicitParam(name = "contentChannelVo",value = "交易渠道表Vo对象",required = true,dataType = "ContentChannelVo")
    public ResponseWrap<Boolean> deleteContentChannel(@RequestBody ContentChannelVo contentChannelVo) {
        Boolean flag = contentChannelFace.deleteContentChannelVo(contentChannelVo.getCheckedIds());
        return ResponseWrapBuild.build(ContentChannelEnum.SUCCEED,flag);
    }

    /***
     * @description 多条件查询交易渠道表列表
     * @param contentChannelVo 交易渠道表Vo对象
     * @return List<ContentChannelVo>
     */
    @PostMapping("list")
    @ApiOperation(value = "多条件查询交易渠道表列表",notes = "多条件查询交易渠道表列表")
    @ApiImplicitParam(name = "contentChannelVo",value = "交易渠道表Vo对象",required = true,dataType = "ContentChannelVo")
    public ResponseWrap<List<ContentChannelVo>> contentChannelList(@RequestBody ContentChannelVo contentChannelVo) {
        List<ContentChannelVo> contentChannelVoList = contentChannelFace.findContentChannelVoList(contentChannelVo);
        return ResponseWrapBuild.build(ContentChannelEnum.SUCCEED,contentChannelVoList);
    }

}
